<?php # Script 2.1 - config.inc.php

/**
 *
 * $Rev:: 19            $:  Revision of last commit
 * $Author:: guy        $:  Author of last commit
 * $Date:: 2010-02-19 1#$:  Date of last commit
 * Comments:
 * Modified from Larry E. Ullman of DMC Insights, Inc.
 * Configuration file does the following things:
 *  - Has site settings in one location.
 *  - Stores URLs and URIs as constants.
 *  - Sets how errors will be handled.
 *
 */

# ******************** #
# ***** SETTINGS ***** #

// Errors are emailed here.
$contact_email = 'guy.chisholm@caret.cam.ac.uk'; 

// Determine whether we're working on a local server
// or on the real server:
if (stristr($_SERVER['HTTP_HOST'], 'local') || (substr($_SERVER['HTTP_HOST'], 0, 7) == '192.168') || (substr($_SERVER['HTTP_HOST'], 0, 4) == '10.0')) {
	$local = TRUE;
} else {
	$local = FALSE;
}

// Determine location of files and the URL of the site:
// Allow for development on different servers.
if ($local) {

	session_start();
	
	// Always debug when running locally:
	//$debug = TRUE;
	
	// Define the constants:
	define ('BASE_URI', '/Users/gc291/Projects/eesc/');
	define ('BASE_URL',	'http://localhost/~gc291/TIS/');
	define ('DB', '/Users/gc291/Projects/DPTD/inc/mysql.conn.inc.php');
	define ('TABLE_PREFIX', '');
	//define ('TABLE_PREFIX', 'tbl_jisc_');
	
} else {

	define ('BASE_URI', '/WWW/SITES/jisc_site/');
	define ('BASE_URL',	'http://www.example.com/');
	define ('DB', '/WWW/SITES/jisc_site/inc/mysql.conn.inc.php');
	define ('TABLE_PREFIX', 'tbl_jisc_');
	
}
	
/* 
 *	Most important setting...
 *	The $debug variable is used to set error management.
 *	To debug a specific page, add this to the index.php page:

if ($p == 'thismodule') $debug = TRUE;
require_once('./includes/config.inc.php');

 *	To debug the entire site, do

$debug = TRUE;

 *	before this next conditional.
 */


// Assume debugging is off. 
if (!isset($debug)) {
	$debug = FALSE;
}
//$debug = TRUE;
# ***** SETTINGS ***** #
# ******************** #


# **************************** #
# ***** ERROR MANAGEMENT ***** #

// Create the error handler.
function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {

	global $debug, $contact_email;
	
	$client = $_SERVER['REMOTE_ADDR'];
	
	// Build the error message.
	$message = "[".date('D M j G:i:s Y')."] [$e_number] [client $client] ";
	$message .= "An error occurred in script '$e_file' on line $e_line: \n$e_message";
	
	// Add the date and time.
	$message .= "\nDate/Time: " . date('n-j-Y H:i:s');
	
	//$message .= "\nUser Agent: " . $_SERVER['HTTP_USER_AGENT'];
	
	// Append $e_vars to the $message.
	$message .= "\n" . print_r ($e_vars, 1);
	
	if ($debug) { // Show the error.
	
		echo "<p class=\"error ui-state-error\"><pre>" . $message . "</pre></p>";

		
	} else { 
	
		// Log the error:
		error_log ($message, 3, "/var/log/php/error.log"); // Send to log file.
		
		// Only print an error message if the error isn't a notice or strict.
		if ( ($e_number != E_NOTICE) && ($e_number < 2048)) {
			echo "<p class=\"error ui-state-error\"><span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: 0.3em;\"></span>Your request could not be completed. We apologize for the inconvenience.  Please quote this date [".date('D M j G:i:s Y')."] when reporting any errors</p>";
		}
		
	} // End of $debug IF.

} // End of my_error_handler() definition.

// Use my error handler:
set_error_handler ('my_error_handler');


# ***** ERROR MANAGEMENT ***** #
# **************************** #
